<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var nums = [1,2,5,6,3,4,7,8];
        var sum=0;
        console.log(nums);
        var res = nums.reduce(function(prev, current) {
           return prev+current; 
        });
        console.log(res);
        sum = res/nums.length;
        alert('平均数为:'+sum);
    </script>
</body>
</html>